package Servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class transServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        ServletContext application=request.getServletContext();
        String user="";
        String username="";
        String json=null;
        user=(String) application.getAttribute("user");
        username=(String)application.getAttribute("username");
        PrintWriter pw=response.getWriter();
        Map map=new HashMap();
        if(null!=user&&!("".equals(user))&&(null!=username&&!("".equals(username)))){
            map.put("user",user);
            map.put("username",username);
            ObjectMapper om=new ObjectMapper();
            json=om.writeValueAsString(map);
        }
        pw.print(json);
        pw.flush();
        pw.close();
    }
}
